#include "myoled.h"
#include "hwctl.h"
#include "stdlib.h"
#include "wiringPi.h"

#define filename "/dev/i2c-3"
static struct display_info disp;

int oled_display(void *array)
{
    oled_clear(&disp);
    hw_pt tmp = NULL;
    if (NULL != array)
    {
        tmp = (hw_pt)array;
        char *buf = tmp->gpio_status == LOW ? " open " : " close ";
        char arr[32];
        memset(arr,0,32);
        strcpy(arr,tmp->dev_name);
        oled_putstrto(&disp, 30, 30,strcat(arr,buf));
        printf("display->%s\n",arr);
        disp.font = font2;
        oled_send_buffer(&disp);
    }
    return 0;
}

int myoled_init(void)
{
    static int e;
    disp.address = OLED_I2C_ADDR;
    disp.font = font2;
    e = oled_open(&disp, filename);
    e = oled_init(&disp);
    oled_clear(&disp);
    return e;
}

void oled_clear(struct display_info *disp) 
{
	memset(disp->buffer, 0, sizeof(disp->buffer));
	oled_send_buffer(disp);
}